"""
提取特征
"""

import cv2
import numpy as np

def grid_feature(im,grid=(9,16)):
    gh=grid[0]
    gw=grid[1]
    h,w = im.shape
    _,im = cv2.threshold(im, 128, 255, cv2.THRESH_BINARY)
    sh = h // gh
    sw = h // gw
    gridFeat = np.zeros((gh*gw))
    for i in range(gh):
        for j in range(gw):
            tmp = im[sh * i:sh * (i+1) + 1, sw*j: sw * (j+1) +1]
            gridFeat[i * gw + j] = np.sum(tmp)
    gridFeat = gridFeat / (np.sum(gridFeat))
    return gridFeat